package com.zyf.user.controller;

import com.zyf.user.model.User;
import com.zyf.user.service.Userservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.util.WebUtils;

import javax.servlet.http.HttpServletRequest;

@RestController
/**
 *  用户xxx
 * @author  zpf
 * @date 2018-
 * @emil  z131@qq.com
 * */
public class UserController {

    @Autowired
    Userservice userservice;
   @GetMapping("/get")
    public String get(HttpServletRequest request){
       String name = WebUtils.getParametersStartingWith(request,null).get("name").toString();
       User user = userservice.get(name);
       return user.getName();
    }

    @PostMapping("/add")
    public String add(HttpServletRequest request){
        String name = WebUtils.getParametersStartingWith(request,null).get("name").toString();
        return userservice.add(name);
    }
}

